package com.guchenbo.example.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author guchenbo
 * @Date 2019/7/3.
 */
public class ThreadLocalTest {
    private static ThreadLocal<Object> local = new ThreadLocal<Object>();
    private static ExecutorService executorService = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 3; i++) {
            executorService.submit(()->{
                Object obj = new Object();
                local.set(obj);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(local.get());
            });
        }
        executorService.shutdown();
    }

}
